import {nanoid} from "nanoid";

export default {
    namespaced: true,
    actions:{
        addPersonWang(context,value){
            if(!value){
                alert("请输入内容")
                return
            }
            if (!value.startsWith("王")) {
                alert("请添加王姓人员");
            }
            const newPerson = {
                id: nanoid(),
                title: value
            };
            context.commit('ADDPERSON',newPerson)
        }
    },
    mutations:{
        ADDPERSON(state, value){
            state.personList.unshift(value)
        }
    },
    state:{
        personList:[{id:1,title:"张三"}]
    },
    getters:{
        getEnglishName(state){
            if(state.personList.length === 0){
                return "";
            }
            return state.personList.map(item => item.title).join(',')
        }
    }
}